////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//                                                                                                                            //
//                                                         WNProject                                                          //
//                                                                                                                            //
//         This file is distributed under the BSD 2-Clause open source license. See Licenses/License.txt for details.         //
//                                                                                                                            //
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

#include "WNScripting/inc/WNTypeNode.h"
#include "WNScripting/inc/WNScriptingAllocations.h"
#include "WNScripting/inc/WNCodeModule.h"
#include "WNScripting/inc/WNTypeManager.h"

using namespace WNScripting;

WNTypeNode::WNTypeNode(const char* _customType) :
    mType(SC_CUSTOM),
    mNumArrayLevels(0){
        COPY_STRING(_customType, mCustomType);
}

WNTypeNode::~WNTypeNode() {
    WN_DELETE(mCustomType);
}
    
void WNTypeNode::AddArrayLevel() {
    mNumArrayLevels += 1;
}

eWNTypeError WNTypeNode::GetType(WNCodeModule& _module, WNScriptType& _outType) const {
    eWNTypeError err = eWNOK;
    if(eWNOK != (err = _module.GetTypeManager().GetTypeByName(mCustomType, _outType))) {
        return(err);
    }
    for(WN_SIZE_T i = 0; i < mNumArrayLevels; ++i) {
        if(eWNOK != (err = _module.GetTypeManager().GetArrayOf(_outType, _outType))) {
            return(err);
        }   
    }
    return(eWNOK);
}
